package com.njxz.demo.controller;

import com.njxz.demo.domain.User;
import com.njxz.demo.domain.result.Result;
import com.njxz.demo.service.IAdminService;
import com.njxz.demo.service.IAdminUserManageService;
import com.njxz.demo.service.IBookCategoryService;
import com.njxz.demo.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/usermanage")
@CrossOrigin
public class AdminUserManageController {
    @Autowired
    private IBookCategoryService bookCategoryService;

    @Autowired
    private IAdminService adminService;

    @Autowired
    private IBookService bookService;

    @Autowired
    private IAdminUserManageService adminUserManageService;

    /**
     * 查询所有用户
     */
    @PostMapping("/getUserList")
    public Result getAllUser() {
         List<User> userList= adminUserManageService.getAllUser();
         if (userList.size()>0){
             return Result.ok(userList);
         }
         return Result.fail();

    }
    /**
     * 根据用户id删除用户
     *
     */
    @PostMapping("/deleteUser")
    public Result deleteUserById(@RequestParam Integer userId) {
        if (adminUserManageService.deleteUserById(userId)==1){
            return Result.ok();
        }
        return Result.fail();
    }
    /**
     * 添加用户
     */
    @PostMapping("/saveUser")
    public Result saveUser(@RequestBody User user) {
        if (adminUserManageService.saveUser(user)==1){
            return Result.ok();
        }
        return Result.fail();
    }

}
